package adv8;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Vector;

import adv7.bank2.Account;

public class ClsTest2 {

	public static void main(String[] args) throws Exception {
		Class c2 = Vector.class;
		Vector v = (Vector) c2.newInstance();
		v.add("dddd");
		System.out.println(v);
		System.out.println(">>>>>>>>>>>>>>>>");
		Class c3 = Account.class;

		// 获得所有的构造方法
		Constructor[] cr = c3.getDeclaredConstructors();
		for (Constructor ct : cr)
			System.out.println(ct);

		// Account ac = (Account) c3.newInstance();
		// System.out.println(ac.getNo() + "," + ac.getMoney());
		// 获得Account只有一个int作为参数的构造方法对象
		Constructor c5 = c3.getDeclaredConstructor(int.class);
		Account ac = (Account) c5.newInstance(30000);
		System.out.println(ac.getNo() + "," + ac.getMoney());
		System.out.println(">>>>>>==列出所有的属性：");
		Field fr[] = c3.getDeclaredFields();
		for (Field f : fr)
			System.out.println(f);
		System.out.println(">>>>改no：");
		Field fno = c3.getDeclaredField("no");
		// obj.no=xxx
		fno.setAccessible(true);
		fno.set(ac, "农行-999999");
		ac.show();
		System.out.println(">>>>>>>>>>>>列出所有的方法>>>>>>>>>>");
		Method mr[] = c3.getDeclaredMethods();
		for (Method m : mr)
			System.out.println(m);
		System.out.println(">>>>>调用setk那个方法");
		Method mk = c3.getDeclaredMethod("setKai", String.class);
		mk.setAccessible(true);
		Object r = mk.invoke(ac, "2018-11-20");
		System.out.println(mk + " 返回了" + r);
		ac.show();
	}
}
